//
//  ShareSheetView.m
//  WidgetTest
//
//  Created by 李明明 on 15/10/15.
//  Copyright © 2015年 李明明. All rights reserved.
//

#import "YShareSheetView.h"
@interface YShareSheetView ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constra;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *one2two;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *two2three;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *three2four;

@end

@implementation YShareSheetView
{
    UIViewController *testVC;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        testVC = [[UIViewController alloc] init];
        testVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [testVC.view addGestureRecognizer:tap];
        [testVC.view addSubview:self];
        
        [window addSubview:testVC.view];
        self.layer.cornerRadius = 10;
        NSLayoutConstraint *leadingCon = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeLeading multiplier:1.0f constant:10];
        NSLayoutConstraint *trailingCon = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeTrailing multiplier:1.0f constant:-10];
        NSLayoutConstraint *bottomCon = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0];
        NSLayoutConstraint *heightCon = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant:180];
        NSArray *contraints = @[leadingCon, trailingCon, bottomCon, heightCon];
        [NSLayoutConstraint activateConstraints:contraints];
    }
    return self;
}
- (void)tap:(UITapGestureRecognizer *)tap
{
    [testVC.view removeFromSuperview];
    [self removeFromSuperview];
}



- (IBAction)cancelAction:(id)sender
{
    self.type(kCancel);
    [self.delegate clickBtns:kCancel];
    [self tap:nil];
}
- (IBAction)firstAction:(id)sender
{
    self.type(kSina);
    [self.delegate clickBtns:kSina];
    [self tap:nil];
}
- (IBAction)secondAction:(id)sender
{
    self.type(kWeChat);
    [self.delegate clickBtns:kWeChat];
    [self tap:nil];
}
- (IBAction)thirdAction:(id)sender
{
    self.type(kQQZones);
    [self.delegate clickBtns:kQQZones];
    [self tap:nil];
}
- (IBAction)forthAction:(id)sender
{
    self.type(kQQfriends);
    [self.delegate clickBtns:kQQfriends];
    [self tap:nil];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
